<?php

require 'module/base/financeHandler.class.php';

class ajax_CODBalance {
	//入口
	public function execute(){
		$operFlg = isset($_REQUEST['operFlg']) ? $_REQUEST['operFlg'] : null;
		switch ($operFlg){
			case 1:
				$this->showList();
				break;
		}
	}
	
	private function showList (){
		global $G_PGLOB;
		
		$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 1;
		$rp = isset($_REQUEST['rp']) ? $_REQUEST['rp'] : 10;
		$sortname = isset($_REQUEST['sortname']) ? $_REQUEST['sortname'] : '';
		$sortorder = isset($_REQUEST['sortorder']) ? $_REQUEST['sortorder'] : '';
		$bill_no = isset($_REQUEST['bill_no']) ? $_REQUEST['bill_no'] : '';
		$package_no = isset($_REQUEST['package_no']) ? $_REQUEST['package_no'] : '';
		$deliver_name = isset($_REQUEST['deliver_name']) ? $_REQUEST['deliver_name'] : '';
		$deliver_mobile = isset($_REQUEST['deliver_mobile']) ? $_REQUEST['deliver_mobile'] : '';
		$startDate = isset($_REQUEST['startDate']) ? $_REQUEST['startDate'] : '';
		$endDate = isset($_REQUEST['endDate']) ? $_REQUEST['endDate'] : '';
		
		$importData = array(
				'page'				=> $page,
				'rp'				=> $rp,
				'sortname'			=> $sortname,
				'sortorder'			=> $sortorder,
				'bill_no'			=> $bill_no,
				'package_no'		=> $package_no,
				'deliver_name'		=> $deliver_name,
				'deliver_mobile'	=> $deliver_mobile,
				'startDate'			=> $startDate,
				'endDate'			=> $endDate
		);
		
		$financeHandler = new financeHandler($G_PGLOB->DBCA);
		
		$result_search = $financeHandler->searchCODBillInfo($importData);
		
		//页面输出数组
		$result_array = array(
				'page' => $_REQUEST['page'],
				'total' => $importData['total'],
				'rows' => array()
		);
		
		if ($result_search){
			foreach ($result_search as $value){
		
				$result_array['rows'][] = array(
						'cell'	=> array(
								$value['package_no'],
								$value['bill_no'],
								$value['createTime'],
								$value['storeName'],
								$value['hdfk_paid'],
								$value['dispatch_time'],
								$value['logistics_name'],
								$value['goods_weight'],
								$value['deliver_name'],
								$value['deliver_mobile'],
								$value['deliver_province'].' '.$value['deliver_city'].' '.$value['deliver_county'].' '.$value['deliver_address']
						)
		
				);
			}
		}
		
		echo json_encode($result_array);
	}
}